exports.communicationManagement = (req, res) => {

    var restfulParams = req.routeInfo.restfulParams;

    var resultData = {};


    //查询媒体传播信息
    function propagationInfo(cb) {

        R.SEND_HTTP(
            req,
            res,
            {
                url: CORE_APIConfig.coreAPI.artMediaCommunicationSearch.Request_Api_Url + "/mc_is_delete/0",
                method: 'POST',
                data: {
                    fields: ['mc_id', 'mc_title_image', 'mc_title', 'mc_create_time'].join(",")
                }
            },
            function (data) {

                resultData.propagationInfo = data.result.data;

                cb();

            }
        )
    }


    //查询每个传播媒体的相关数据
    function queryForEachMediaData(cb) {

        F.SerialEach(resultData.propagationInfo, function (item, index, callback) {

            //查询阅读，分享，成交数
            function propagationRelationCount(eachCb) {

                R.SEND_HTTP(
                    req,
                    res,
                    {
                        url: config.external_server.apiAddress + "/organization/search_art_product_user_read_record/apuur_mcid/" + item.mc_id,
                        method: 'POST',
                        data: {
                            fields: ['apurr_id', 'apurr_read_count', 'apurr_share_count', 'apurr_status',].join(",")
                        }
                    },
                    function (data) {

                        var propagationData = data.result.data;

                        var browseCount = 0;
                        var shareCount = 0;
                        var buyCount = 0;
                        if (propagationData.length > 0) {
                            for (var i = 0; i < propagationData.length; i++) {
                                browseCount += parseInt(propagationData[i].apurr_read_count);
                                shareCount += parseInt(propagationData[i].apurr_share_count);
                                if (propagationData[i].apurr_status == 1) {
                                    buyCount++
                                }
                            }
                        }

                        item.browseCount = browseCount;
                        item.shareCount = shareCount;
                        item.buyCount = buyCount;

                        eachCb();

                    }
                )
            }


            F.Parallel([
                propagationRelationCount,
            ], () => {
                callback();
            })

        }, cb)

    }
    F.Serial([
        propagationInfo,
        queryForEachMediaData,
    ], () => {
        RES.successResponse(res, resultData);
    })


}